package com.example.demo.service;

import com.example.demo.domain.Teacher;
import com.example.demo.repository.TeacherRespository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherService {
    @Autowired
    private TeacherRespository teacherRespository;

    /**
     * 更新或添加老师信息
     * @param entities  老师信息
     * @return
     */
    public Teacher saveTeachers(Teacher entities){
        return teacherRespository.saveAndFlush(entities);
    }

    /**
     * 查询所有老师信息
     * @return
     */
    public List<Teacher> findAll(){
        return teacherRespository.findAll();
    }

    /**
     * 按工号查询老师信息
     * @param id
     * @return
     */
    public Teacher findByTid(String id){
        return  teacherRespository.findByTid(id);
    }

    /**
     * 找到最晚入职的老师
     * @return
     */
    public List<Teacher> findLatestTeachers(){
        return teacherRespository.findLastestTeachers();
    }
    /**
     * 按工号删除老师信息
     * @param id
     */
    public void deleteById(Integer id){
        teacherRespository.deleteById(id);
    }

    /**
     * 保存老师信息
     * @param t
     */
    public void saveTeacher(Teacher t){
        teacherRespository.saveAndFlush(t);
    }
}
